package com.zhiqihang.ziqihangservercourse.service.impl;


import com.zhiqihang.course.Course;
import com.zhiqihang.course.CourseCode;
import com.zhiqihang.result.JsonResult;
import com.zhiqihang.ziqihangservercourse.repository.CourseRepository;
import com.zhiqihang.ziqihangservercourse.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @ClassName CourseServiceImpl
 * @Description Violet
 * @Author 86183
 * @Date 2024/7/26 17:25
 * @Version 1.0
 */
@Service
@Slf4j
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseRepository courseRepository;

    @Override
    public JsonResult findById(Long id) {
        Optional<Course> optional = courseRepository.findById(id);
        if (optional.isPresent()) {
            return JsonResult.ok(optional.get());
        }
        return new JsonResult(CourseCode.COURSE_NOT_FOUND,null);
    }
}
